﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace DARE.Save.DataStructures
{
    public class CSprite3DData : ISaveData
    {
        public string Name;
        public string Texture;
        public Color[] textureData;
        public Vector2 SpriteOffset;
        public bool IsSizeFixed;
        public Color Color;
        public Vector2 Size;
        public Vector3 Offset;

        public virtual void FillDataStructure(object spr3D)
        {
            CSprite3D sprite3D = spr3D as CSprite3D;
            if (sprite3D == null)
                return;
            Name = sprite3D.Name;
            Texture = DARE.CResourceMgr.GetResourceName(sprite3D.Texture);
            if (Texture == null)
            {
                textureData = new Microsoft.Xna.Framework.Color[sprite3D.Texture.Width * sprite3D.Texture.Height];
                sprite3D.Texture.GetData(textureData);
            }
            SpriteOffset = sprite3D.SpriteOffset;
            IsSizeFixed = sprite3D.IsSizeFixed;
            Color = sprite3D.Color;
            Size = sprite3D.Size;
            Offset = sprite3D.Offset;
        }

        public virtual void FillFromDataStructure(out object sprite3D, params object[] paramsData)
        {
            CSprite3D spr = CreateInstance();
            spr.Name = Name;
            spr.Texture = DARE.CResourceMgr.Load<Texture2D>(Texture);
            spr.SpriteOffset = SpriteOffset;
            spr.IsSizeFixed = IsSizeFixed;
            spr.Color = Color;
            spr.Size = Size;
            spr.Offset = Offset;

            sprite3D = spr;
        }

        public virtual CSprite3D CreateInstance()
        {
            return new CSprite3D();
        }
    }
}
